#include "Plane.h"


CPlane::CPlane(void)
{
	m_IsMesh = false;
}


CPlane::~CPlane(void)
{
	delete m_NormalVector;
}

/*
	Method checks if ray intersects a plane or two particular cases occur.

	Returns:
	0 - intersects
	1 -	ray is parallel to plane						- First particular case
	2 - intersection occurs in front of ray's origin		- Second particular case
*/
int	CPlane::Intersect(CRay& _ray, CVector& _vecIntersec, CVector& _vecIntersec2 = CVector())
{
	CVector p0 = *m_Origin;
	CVector l0 = (*_ray.GetOrigin());
	CVector	l = (*_ray.GetDirection());
	float denom = CVector::DotProduct(l, (*m_NormalVector));

	if (FEQUAL(denom, 0.0f))
		return 1;

	float t = CVector::DotProduct((l0 - p0), (*m_NormalVector)) / denom;

	if (t < 0)
		return 2;

	_vecIntersec = _ray.ParametricEquation(t);

	return 0;
}
